﻿create procedure [dbo].[usp_TargetSiteInsert]
	@ContainsGenericParameters bit
	, @DeclaringType nvarchar(255)
	, @IsAbstract bit
	, @IsAssembly bit
	, @IsConstructor bit
	, @IsFamily bit
	, @IsFamilyAndAssembly bit
	, @IsFamilyOrAssembly bit
	, @IsFinal bit
	, @IsGenericMethod bit
	, @IsGenericMethodDefinition bit
	, @IsHideBySignature bit
	, @IsPrivate bit
	, @IsPublic bit
	, @IsSpecialName bit
	, @IsStatic bit
	, @IsVirtual bit
	, @MemberType nvarchar(255)
	, @Module nvarchar(255)
	, @Name nvarchar(255)
as

begin try
	
	begin transaction
	
		if not exists(select * from [dbo].[TargetSite] where [ContainsGenericParameters] = @ContainsGenericParameters and 
														 [DeclaringType] = @DeclaringType and
		                                                 [IsAbstract] = @IsAbstract and
			                                             [IsAssembly] = @IsAssembly and 
				                                         [IsConstructor] = @IsConstructor and
					                                     [IsFamily] = @IsFamily and
						                                 [IsFamilyAndAssembly] = @IsFamilyAndAssembly and
						                                 [IsFamilyOrAssembly] = @IsFamilyOrAssembly and
						                                 [IsFinal] = @IsFinal and
						                                 [IsGenericMethod] = @IsGenericMethod and
						                                 [IsGenericMethodDefinition] = @IsGenericMethodDefinition and
						                                 [IsHideBySignature] = @IsHideBySignature and
						                                 [IsPrivate] = @IsPrivate and
						                                 [IsPublic] = @IsPublic and
						                                 [IsSpecialName] = @IsSpecialName and
						                                 [IsStatic] = @IsStatic and
						                                 [IsVirtual] = @IsVirtual and
						                                 [MemberType] = @MemberType and
						                                 [Module] = @Module and
						                                 [Name] = @Name)
			begin
										                              
				insert [dbo].[TargetSite]
				(
				    [ContainsGenericParameters]
					, [DeclaringType]
					, [IsAbstract]
					, [IsAssembly]
					, [IsConstructor]
					, [IsFamily]
					, [IsFamilyAndAssembly]
					, [IsFamilyOrAssembly]
					, [IsFinal]
					, [IsGenericMethod]
					, [IsGenericMethodDefinition]
					, [IsHideBySignature]
					, [IsPrivate]
					, [IsPublic]
					, [IsSpecialName]
					, [IsStatic]
					, [IsVirtual]
					, [MemberType]
					, [Module]
					, [Name]				
			    )
				values
				(
					@ContainsGenericParameters
					, @DeclaringType
					, @IsAbstract
					, @IsAssembly
					, @IsConstructor
					, @IsFamily
					, @IsFamilyAndAssembly
					, @IsFamilyOrAssembly
					, @IsFinal
					, @IsGenericMethod
					, @IsGenericMethodDefinition
					, @IsHideBySignature
					, @IsPrivate
					, @IsPublic
					, @IsSpecialName
					, @IsStatic
					, @IsVirtual
					, @MemberType
					, @Module
					, @Name
				)
				
				select [TargetSiteId], [ConcurrencyId], [Created], [Updated] from [dbo].[TargetSite] where @@rowcount > 0 and TargetSiteId = scope_identity()
			
			end
			
		else
			
			begin
			
				select [TargetSiteId], [ConcurrencyId], [Created], [Updated] from [dbo].[TargetSite] where [ContainsGenericParameters] = @ContainsGenericParameters and 
														                                           [DeclaringType] = @DeclaringType and
		                                                                                           [IsAbstract] = @IsAbstract and
			                                                                                       [IsAssembly] = @IsAssembly and 
				                                                                                   [IsConstructor] = @IsConstructor and
					                                                                               [IsFamily] = @IsFamily and
						                                                                           [IsFamilyAndAssembly] = @IsFamilyAndAssembly and
						                                                                           [IsFamilyOrAssembly] = @IsFamilyOrAssembly and
						                                                                           [IsFinal] = @IsFinal and
						                                                                           [IsGenericMethod] = @IsGenericMethod and
						                                                                           [IsGenericMethodDefinition] = @IsGenericMethodDefinition and
						                                                                           [IsHideBySignature] = @IsHideBySignature and
						                                                                           [IsPrivate] = @IsPrivate and
						                                                                           [IsPublic] = @IsPublic and
						                                                                           [IsSpecialName] = @IsSpecialName and
						                                                                           [IsStatic] = @IsStatic and
						                                                                           [IsVirtual] = @IsVirtual and
						                                                                           [MemberType] = @MemberType and
						                                                                           [Module] = @Module and
						                                                                           [Name] = @Name
			end
	
	commit transaction

end try
	
begin catch
	if @@trancount > 0
	begin
		rollback transaction;
	end
	execute [dbo].[usp_SqlErrorInsert]
end catch


